require(['init'], function () {
    var $pagination = $('#js-pagination')
    var pagination;
    //编辑和添加的DOm
    var needPw=true;
    var $enrollDom = $('<div class="paraList" id="J_enroll_wrap">'+
            '<input class="form-control" type="hidden" name="fuid" >'+
            '<h4 style="margin-left:15px">'+i18next.t('info.classininfo')+'：</h4>'+
            '<div class="li line">'+
                '<div class="title">'+
                    '<label style="color:red";position:="" relative;left:="" -2px;="">*</label><span>'+i18next.t('info.classinaccountnumber')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="ClassInNo" data-formcheck="length">' +
                    '<input class=""  type="button"  name="" value="检测" id="classIntest" style="margin-left:10px;" style="display:none">' +
                    '<input class=""  type="button"  name="reset" value="重置密码"  id="resetpassword" style="margin-left:10px;">' +
                    '<div style="margin-top:4px;color:#2ba76c;font-size:12px;display:none" id="prompt">'+i18next.t('input.exist')+'</div>'+
                '</div>'+
            '</div>'+
            '<div class="li pw" style="display:none">'+
                '<div class="title">'+
                    '<span>'+i18next.t('input.originalpassword')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="pw" >' +
                    '<div style="margin-top:4px;color:red;font-size:12px;display:none" id="noprompt">'+i18next.t('input.unregistered')+'</div>'+
                '</div>'+
            '</div>'+
            '<h4 style="clear:both;margin-left:15px;padding-top:22px;">'+i18next.t('info.basicinformation')+'：</h4>'+
            '<div class="li">'+
                '<div class="title required">'+
                 '<label style="color:red" ;position:="" relative;left:="" -2px;="">*</label><span>'+i18next.t('table.chinesename')+'：</span>' +
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control focus" data-formcheck="length" type="text" name="cn_name" >' +
                    '<div class="inputErrorTips" style="display: none;"></div>' +
                '</div>'+
            '</div>'+
            '<div class="li">'+
                '<div class="title ">'+
                   '<span>'+i18next.t('table.englishname')+'：</span>' +
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="en_name" >' +
                '</div>'+
            '</div>'+
            '<div class="li">'+
                '<div class="title required">'+
                   ' <label style="color:red" ;position:="" relative;left:="" -2px;="">*</label><span>'+i18next.t('info.cellphonenumber')+'：</span>' +
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control"  type="text" name="phone" data-formcheck="length">' +
                    '<input type="hidden" name="tuid">'+
                '</div>'+
            '</div>'+
           '<div class="li">'+
                '<div class="title required">'+
                   '<span>'+i18next.t('info.email')+'：</span>' +
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" data-formcheck="email" type="text" name="email" >' +
                    '<input type="hidden" name="tuid">'+
                '</div>'+
            '</div>'+
            '<div class="li">'+
                '<div class="title">'+
                    '<span>'+i18next.t('table.birth')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input type="text" class="form-control" size="16" data-type="date-input" name="dateofbirth" data-valuetype="single" data-value="0" value="选择时间" readonly="readonly" style="width:160px;" placeholder="选择时间">' +
                '</div>'+
            '</div>'+

            '<div class="li">'+
                '<div class="title">'+
                   '<span>'+i18next.t('table.grade')+'：</span>' +
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="gradeno" >' +
                '</div>'+
            '</div>'+
            '<div class="li">' +
                '<div class="title">' +
                    '<span>'+i18next.t('info.sex')+'：</span>' +
                '</div>'+
                '<div class="genderWrap" style="position:relative;top:3px">' +
                 '<span>'+
                    '<span class="icon icon-size-16 icon-radio" data-type="checkbox">'+
                        '<input type="checkbox" name="sex" data-checkedmax="1" value="0">'+
                    '</span><span data-type="label">'+i18next.t('sex.man')+'</span>'+
                    '</span>&nbsp;'+
                    '<span>'+
                    '<span class="icon icon-size-16 icon-radio" data-type="checkbox" style="margin-left: 18px;">' +
                        '<input type="checkbox" name="sex" data-checkedmax="1" value="1">'+
                    '</span><span data-type="label">'+i18next.t('sex.woman')+'</span>'+
                    '<span>'+
                    // '<div class="J_gender_help"></div>'+
                '</div>'+
            '</div>' +
            '<div class="li">'+
                '<div class="title">'+
                    '<span>'+i18next.t('table.registrationdate')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                   '<input type="text" class="form-control" size="16" data-type="date-input" name="signupDate" data-valuetype="single" data-value="0" value="选择时间" readonly="readonly" style="width:170px;">' +
                '</div>'+
            '</div>'+
            '<div class="li">'+
                '<div class="title">'+
                   '<span>'+i18next.t('table.school')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="schoolname" >' +
                '</div>'+
            '</div>'+

            '<div class="li">'+
                '<div class="title">'+
                '<span>'+i18next.t('table.bookname')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="textbookname" >' +
                '</div>'+
            '</div>'+

            '<div class="li">'+
                '<div class="title">'+
                   '<span>'+i18next.t('table.tutorialsubjects')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="needsubject"  >' +
                '</div>'+
            '</div>'+


            '<div class="li">'+
                '<div class="title">'+
              '<span>'+i18next.t('table.tutorialcourse')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="firstLessonContent"  >' +
                '</div>'+
            '</div>'+

            '<div class="li">'+
                '<div class="title">'+
                    '<span>'+i18next.t('table.difficultpoints')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="difficulty"  >' +
                '</div>'+
            '</div>'+

            '<div class="li">'+
                '<div class="title">'+
                    '<span>'+i18next.t('table.schoolrecord')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="currentgrades"  >' +
                '</div>'+
            '</div>'+
            '<div class="li">'+
                '<div class="title">'+
                    '<span>'+i18next.t('table.coursedates')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control " type="text" name="classdate" >' +

                '</div>'+
            '</div>'+

            '<div class="li">'+
                '<div class="title">'+
                    '<span>'+i18next.t('table.schooltime')+'：</span>'+
                '</div>'+
                '<div class="content">'+
                    '<input class="form-control" type="text" name="lessondate" >' +
                '</div>'+
            '</div>'+
            '<div class="li">'+
                '<div class="title" >'+
                  '<span>'+i18next.t('table.examination')+'：</span>'+
                '</div>'+
                '<div class="content" >' +
                    '<input class="form-control" type="text" name="curriculum" >' +
                '</div>'+
	      '</div>'+
            '<h4 style="clear:both;margin-left:15px;padding-top:22px;">'+i18next.t('table.remarksmessage')+'：</h4>'+

            '<div class="li line">'+
                '<div class="title" >'+
                  '<span>'+i18next.t('info.remark1')+'：</span>'+
                '</div>'+
                '<div class="content" >' +
                  '<input class="form-control" style="width:95%" type="text" name="remark1" >' +
                '</div>'+
            '</div>'+
            '<div class="li line">'+
                '<div class="title" >'+
                  '<span>'+i18next.t('info.remark2')+'：</span>'+
                '</div>'+
                '<div class="content" >' +
                  '<input class="form-control" style="width:95%" type="text" name="remark2" >' +
                '</div>'+
            '</div>'+
                '<div class="li line">'+
                '<div class="title" >'+
                  '<span>'+i18next.t('info.remark3')+'：</span>'+
                '</div>'+
                '<div class="content" >' +
                  '<input class="form-control" style="width:95%" type="text" name="remark3" >' +
                '</div>'+
            '</div>'+
	  '</div>');
    $enrollDom.find("#resetpassword").val(i18next.t('input.resetpassword'))
    //点击预约的DOM
    var $AboutClass = $('<div class="teacher-appoint" id="J_teacher_appoint" style="width:100%;">' +

              '<input type="hidden" id="studentuid"><input type="hidden" id="fuid">' +
              '<input type="hidden" id="studentname" style="margin-right:15px;"><input type="hidden" id="needsubject">' +

              '<div class=""  style="width:55%; float: left; border-bottom：none !important;overflow:auto;margin-top: 20px;">' +
                   '<div class="line"></div>' +
                  '<div class="topbar clearafter" style="height:94px;">' +

                      '<div class="teacher-search" >' +
                       '<p><a href="javascript:;">'+i18next.t('info.studentname')+'：</a><span id="studentname1" style="margin-right:15px;"></span>' +
                        '<a href="javascript:;">'+i18next.t('table.need')+'：</a><span id="needsubject1" ></span></p></br>' +
                          '<span>'+i18next.t('table.teacherquery')+'：</span>'+
                          '<input type="text" id="J_date_search" class="form-control" data-type="date-input" data-tips="请选择日期范围" data-valuetype="range" readonly="" value="请选择日期范围" style="width: 210px;">' +
                          '<span style="margin-left:20px;">'+i18next.t('course.coursetype')+'：</span><select id="cource" ></select>' +
                      '</div>'+
                  '</div>'+
                  '<div class="wrap">'+

                      '<table class="table" id="J_teacherlist_select">'+
                          '<thead>' +
                            '<th>'+i18next.t('table.no')+'</th>' +
                             '<th>'+i18next.t('table.namee')+'</th>'+
                             '<th>'+i18next.t('table.startdate')+'</th>'+
                             '<th>'+i18next.t('table.enddate')+'</th>'+
                             '<th>'+i18next.t('table.remainingquota')+'</th>'+
                             '<th>'+i18next.t('table.choice')+'</th>'+
                          '</thead>'+
                          '<tbody id="J_teacherlist_data"></tbody>'+
                      '</table>'+
                  '</div>'+
              '</div>'+

              '<div class="timelist-search" style="width: 42%; float: right; margin-left: 30px; height:auto; border-left: 1px solid #ccc; margin-top: 20px; ">' +
                  '<div class="teacher">'+
                      '<span style="margin-left:15px;">'+i18next.t('info.teachername')+'：</span>' +
                      '<span id="J_teachername"></span>'+
                       '<ul class="teacherRemark" style="display:inline-block;margin-left:30px;"></ul>'+
                  '</div>'+
                  '<div class="duration"></div>' +
                  '<div class="appoint-section23" style="margin-left:15px;">'+
                   '</div>' +
                '</div>' +
                 '<div style="width: 42%; float: right; margin-left: 30px; border-bottom：none; height: 980px;  border-left: 1px solid #ccc; margin-top: 20px; display:none" class="prompt">' +
                        '<p style="margin-top:154px;margin-left:77px;">'+i18next.t('table.clickleft')+'</p>' +
                '</div>' +
          '</div>');

      $AboutClass.find('.line').css({
          "width": "1px",
          "height": "326px",
          "background": "#ccc",
          "position": "absolute",
          "left": "598px",
          "top": "30px",
          "z-index":"10000"
      })
    //获取数据
    function EnrollList(querystr, cb) {
        var url ='/api/demoments';
        var query = {}
        if(querystr) {
            query = querystr
        }
        ajaxMethod({
            url: url,
            data: query,
            success:function(data){
              cb && cb(data)
                if(data.list.length == 0) {
                    $('#J_enrollment').html('<div style="margin-top: 50px;text-align: center;">'+i18next.t('input.nullresults')+'</div>');
                    $pagination.hide()
                    return;
                }
                var $enrollmentTable = $('#J_enrollment').html('')
                var $thead = $('<thead>\
                <tr>\
                    <th>'+i18next.t('table.no')+'</th>\
                    <th>'+i18next.t('table.name')+'</th>\
                    <th>'+i18next.t('info.classinaccountnumber')+'</th>\
                    <th>'+i18next.t('table.birth')+'</th>\
                    <th>'+i18next.t('table.grade')+'</th>\
                    <th>'+i18next.t('table.registrationdate')+'</th>\
                    <th>'+i18next.t('table.need')+'</th>\
                    <th>'+i18next.t('info.teachername')+'</th>\
                    <th>'+i18next.t('table.start')+'</th>\
                    <th>'+i18next.t('table.time')+'</th>\
                    <th>'+i18next.t('table.duration')+'</th>\
                    <th>'+i18next.t('table.orderhandle')+'</th>\
                    <th>'+i18next.t('table.handle')+'</th>\
                </tr>\
            </thead>').appendTo($enrollmentTable)
            var $tbody = $('<tbody></tbody>').appendTo($enrollmentTable)
            //上课时长
            function getDurationMinute(begindate, enddate) {
                if (begindate != null || enddate != null) {
                    var beginTime = +new Date(begindate.replace('T', ' '));
                    var endTime = +new Date(enddate.replace('T', ' '));
                    return (endTime - beginTime) / (60 * 1000) + i18next.t('table.minute');
                } else {
                    return '--';
                }
            }
            $.each(data.list, function (index, item) {
                var begindaten = '--';
                var classTime = '--';
                if (item.begintime != null || item.endtime != null) {
                    begindate = formatTime(item.begintime);
                    begindaten = begindate.substr(0,10);
                    classTime = begindate.substr(11, 5);
                }
                var fuid = item.formuid;
                var studentuid = item.studentuid;
                var dateofbirth="";
                var $enroll = $('<tr class="enroll" data-uid="' + fuid + '"></tr>');
                $enroll.append('<td>1</td>');
                $enroll.append('<td>' + item.chinesename + '</td>');
                $enroll.append('<td>' + item.ClassInNo + '</td>');
                $enroll.append('<td>' + (item.dateofbirth ? item.dateofbirth.substr(0, 10) : '--')+ '</td>');
                $enroll.append('<td>' + item.gradeno + '</td>');
                $enroll.append('<td>' + (item.signupDate ? item.signupDate.substr(0, 10) : '--') + '</td>');
                $enroll.append('<td>' + item.needsubject + '</td>');
                $enroll.append('<td style="color:#383636">' + item.teachername + '</td>');
                $enroll.append('<td style="color:#383636">' + begindaten + '</td>');
                $enroll.append('<td style="color:#383636">' + classTime + '</td>');
                $enroll.append('<td style="color:#383636">' + getDurationMinute(item.begintime, item.endtime) + '</td>');
                var $yuyue = $('<td></td>').appendTo($enroll);
                var $yueyueBtn = $('<a href="javascript:;"><span class="btn"></span></a>').appendTo($yuyue);
                var $handleTd = $('<td></td>').appendTo($enroll);
                var $editbtn = $('<a  class="ml5"><span class="btn btn-primary btn-sm btn-inverse">'+i18next.t('table.compile')+'</span></a>').appendTo($handleTd);
                var $deletebtn = $('<a href="javascript:;"><span class="btn btn-danger btn-sm btn-inverse">'+i18next.t('table.delete')+'</span></a>').appendTo($handleTd);
                //编辑学生
                $editbtn.on('click', function () {
                    $enrollDom.find("input[name=cn_name]").attr("readonly","readonly");
                    $enrollDom.find("input[name=ClassInNo]").attr("readonly","readonly");
                    loadEnrollData(fuid);
                    $enrollDom.find('#classIntest').hide();
                    var popUpBox = new PopUpBox({
                        type: 'dom',
                        style: 'default contentScroll',
                        submitBtnType: 'confirm',
                        titleText: i18next.t('popupbox.editcontent'),//请输入编辑内容
                        show: true,
                        keySubmit: false,
                        content: $enrollDom,
                        callback: {
                            yes: function (e) {
                              var phone = $enrollDom.find('[name=phone]').val();
                              var ClassInNo= $enrollDom.find('[name=ClassInNo]').val();
                              var fullname = $enrollDom.find('[name=cn_name]').val();
                              if(phone==""||ClassInNo==""||fullname==""){
                                return false;
                              }
                              bindSubmit();
                            }
                        },
                        position: {
                            width: 656,
                            height: 554
                        }
                    })
                    var $genderWrap = $enrollDom.find('.genderWrap');
                    $(".popUpBoxFg").find('.close').on("click",function(){
                        window.location.reload();
                    })
                })
                //删除
                $deletebtn.on('click', function () {
                    var popUpBox = new PopUpBox({
                        type: 'dom',
                        style: 'default contentScroll',
                        submitBtnType: 'confirm',
                        titleText: i18next.t('popupbox.warmprompt'),//'温馨提示'
                        show: true,
                        content: '<p style="padding-left: 30px; padding-top: 30px;">'+i18next.t('popupbox.studentyue')+'</p>',//学生的约课信息会一并删除 ，您确定要删除吗？
                        callback: {
                            yes: function (e) {
                                ajaxMethod({
                                    url: '/api/demoment/' + fuid,
                                    type: "delete",
                                    success: function () {
                                        //EnrollList();
                                        pagination.updateData();
                                    }
                                });
                            }
                        },
                        position: {
                            width: 400,
                            height: 200
                        }
                    })

                })
                //判断显示预约还是取消
                if (item.status == 1) {
                    $enroll.attr('class', 'v1');
                    $yueyueBtn.find('span').text(i18next.t('table.cancel')).addClass('btn btn-default btn-sm');
                    $yueyueBtn.on('click', function () {
                        var popUpBox = new PopUpBox({
                            type: 'dom',
                            style: 'default contentScroll',
                            submitBtnType: 'confirm',
                            titleText: i18next.t('popupbox.warmprompt'),//温馨提示
                            show: true,
                            content: '<p style="padding-left: 30px; padding-top: 30px;">'+i18next.t('popupbox.cancelcourse')+'</p>',//确定时候取消该课程
                            callback: {
                                yes: function (e) {
                                    ajaxMethod({
                                        url:"/api/demoment/"+fuid+"/unappint",
                                        type: 'put',
                                        success: function (data) {
                                            window.location.reload();
                                        }
                                    })
                                }
                            },
                            position: {
                                width: 400,
                                height:200
                            }
                        })
                    })
                } else {
                    $enroll.attr('class', 'v2');
                    $yueyueBtn.find('span').text(i18next.t('course.aboutclass')).addClass('btn btn-primary btn-sm btn-inverse');
                    $yueyueBtn.on('click',function(){
                        $AboutClass.find('#fuid').val(item.formuid);
                        $AboutClass.find('#studentuid').val(item.studentuid);
                        $AboutClass.find('#studentname').val(item.chinesename);
                        $AboutClass.find('#needsubject').val(item.needsubject);
                        appointTeacher();//默认显示时间和教师列表
                        coursetypes();//课程类型显示
                        var popUpBox = new PopUpBox({
                            type: 'dom',
                            style: 'default contentScroll',
                            submitBtnType:false,
                            titleText: i18next.t('popupbox.pleaseselectteacher'),//请选择老师
                            show: true,
                            content: $AboutClass,
                            callback: {
                                yes: function (e) {
                                }
                            },
                            position: {
                                width: 1042,
                                height:510,
                            }
                        })
                    })
                }
                $tbody.append($enroll)
                //排序
                var len = $('table tr').length;
                for (var i = 1; i < len; i++) {
                    $('table tr:eq(' + i + ') td:first').text(i);
                }
                //字段为null的处理
                $tbody.find("tr").each(function () {
                    var tdhtml = $(this).children();
                    $.each(tdhtml, function (i, t) {
                        $(t).text() == 'null' ? $(t).text('--') : $(t).text()
                        $(t).text() == 'undefined' ? $(t).text('--') : $(t).text()
                        $(t).text() == i18next.t('table.selecttime') ? $(t).text('--') : $(t).text()
                        $(t).text() == '' ? $(t).text('--') : $(t).text()
                        $(t).text() == '0000-00-00' ? $(t).text('--') : $(t).text()
                    })
                });

            })
                $pagination.show()
            }
        })
     }




     //检测
     var registerDefaultPwd="";
     ajaxMethod({
       url: '/api/organization/1',
       type: 'get',
       success:function(data){
         registerDefaultPwd=data.registerDefaultPwd;
       }
     })
     function classIn(){
      var classin_nov="";
      $enrollDom.find('[name="ClassInNo"]').on("blur",function(){
        if($enrollDom.find('[name="ClassInNo"]').val()!=""){
          classIntest();
        }else{
          return false;
        }
      })

      function  classIntest(){
        classin_nov=$enrollDom.find('[name="ClassInNo"]').val();
        ajaxMethod({
          url: '/api/eeo/check',
          method: 'post',
          data: {account:classin_nov},
          success: function (data) {
            if(data=="true"){
              $enrollDom.find('.pw').hide();
              $enrollDom.find('#prompt').show();
              $enrollDom.find('#noprompt').hide();
              $enrollDom.find("#resetpassword").attr("disabled",false)
              needPw=false;
            }else if(data=="true"||classin_nov!=""){
              $enrollDom.find('.pw').show();
              $enrollDom.find('#prompt').hide();
              $enrollDom.find('#noprompt').show();
              $enrollDom.find('[name="pw"]').val(registerDefaultPwd);
              $enrollDom.find("#resetpassword").attr("disabled",true)
              needPw=true;
            }
          }

       })

      }
    }
    $enrollDom.find('[name="pw"]').on('blur',function(){
      if($enrollDom.find('[name="pw"]').val()!=""){
        $enrollDom.find('#prompt').hide();
        $enrollDom.find('#noprompt').hide();
      }else{
        $enrollDom.find('#noprompt').show();
      }
    })
    //重置密码
    var account="";
    $enrollDom.find("#resetpassword").on('click',function(){
      account=$enrollDom.find('[name="ClassInNo"]').val();
        // var ClassInNov= $Addstudent.find('[name="ClassInNo"]').val();
        // if(ClassInNov!=""){
        //     $Addstudent.find("#resetpassword").attr("disabled",false)
        // }else{
        //     $Addstudent.find("#resetpassword").attr("disabled",true)
        // }
        var $ClassInDom=$('<div class="formList" id="J_teacheradd_wrap" style="margin-top:12px;">\
          <div class="formLi" >\
            <div class="formLi" >\
              <div class="formTitle required">\
                  <span>'+i18next.t('reset.newpassword')+'</span>\
              </div>\
              <div class="formContent">\
                  <input class="form-control" data-formcheck="length" type="text"  name="passwordnew" style="width:226px;">\
              </div>\
          </div>\
          <div class="formLi" >\
              <div class="formTitle required">\
                  <span>'+i18next.t('reset.confirmnewpassword')+'</span>\
              </div>\
              <div class="formContent">\
                  <input class="form-control" data-formcheck="length" type="text"  name="passwordold" style="width:226px;">\
                  <p style="color:red;display:none;margin-top:30px;" class="p">'+i18next.t('reset.twice')+'</p>\
              </div>\
            </div>\
          </div>');
          var popUpBox = new PopUpBox({
              ype: 'dom',
              style: 'default autoResize',
              submitBtnType:'alert',
              closeClear:false,
              titleText:i18next.t('popupbox.setpassword'),//请输入设置的密码
              show: true,
              content: $ClassInDom,
              callback: {
                  yes: function (e) {
                    var passwordold=$ClassInDom.find('[name="passwordold"]').val();
                    var passwordnew=$ClassInDom.find('[name="passwordnew"]').val();
                    if(passwordold!=""||passwordnew!=""){
                      if(passwordold!=passwordnew){
                        $('.p').show();
                        return false;
                      }else{
                          $('.p').hide();
                          ajaxMethod({
                              url: '/api/eeo/reset',
                              method: 'post',
                              data: {account:account,
                                    password:passwordold
                                },
                              success: function (data) {
                              }
                           })
                      }
                    }else{
                      return false;
                    }
                }
              },
              position: {
                  width: 450,
                  height:304,
              }
          })
          popUpBox.submitBtnBox.$dom.css('text-align', 'right')
          $(".popUpBoxFg").find('.close').show();
        })
    //点击添加按钮功能
    $('#addenroll').on('click', function () {
      $enrollDom.find("#classIntest").hide();
      $enrollDom.find("#resetpassword").hide();
      classIn();
      $enrollDom.find("input[name=cn_name]").removeAttr("readonly");
      $enrollDom.find("input[name=phone]").removeAttr("readonly");
      $enrollDom.find("input[type='text']").val("");
      var $genderWrap = $enrollDom.find('.genderWrap');
      $genderWrap.find("span").removeClass("checked");
      var signupDateD = new Date().Format('YYYY-MM-DD');
      $enrollDom.find('[name=signupDate]').val(signupDateD);
      var popUpBox = new PopUpBox({
            type: 'dom',
            style: 'default contentScroll',
            submitBtnType: 'confirm',
            titleText:i18next.t('popupbox.pleasecontent') ,//'请填写内容'
            show: true,
            keySubmit: false,
            content: $enrollDom,
            callback: {
                'yes': function (e) {
                  var cnName = $enrollDom.find('[name=cn_name]').val();
                  var phone = $enrollDom.find('[name=phone]').val();
                  var ClassInNo= $enrollDom.find('[name=ClassInNo]').val();
                  var fullname = $enrollDom.find('[name=en_name]').val();
                  var dateofbirth = $enrollDom.find('[name=dateofbirth]').val();
                  var curriculum = $enrollDom.find('[name=curriculum]').val();
                  var needsubject = $enrollDom.find('[name=needsubject]').val();
                  var email = $enrollDom.find('[name=email]').val();
                  var classdate = $enrollDom.find('[name=classdate]').val();
                  var gradeno = $enrollDom.find('[name=gradeno]').val();
                  var textbookname = $enrollDom.find('[name=textbookname]').val();
                  var firstLessonContent = $enrollDom.find('[name=firstLessonContent]').val();
                  var difficulty = $enrollDom.find('[name=difficulty]').val();
                  var lessondate = $enrollDom.find('[name=lessondate]').val();
                  var currentgrades = $enrollDom.find('[name=currentgrades]').val();
                  var schoolname = $enrollDom.find('[name=schoolname]').val();
                  var fuid = $enrollDom.find('[name=fuid]').val();
                  var signupDate= $enrollDom.find('[name=signupDate]').val();
                  var sex= $enrollDom.find('[name=sex]').val();
		               var remark1 = $enrollDom.find('[name=remark1]').val()
                  var remark2 = $enrollDom.find('[name=remark2]').val()
                  var remark3 = $enrollDom.find('[name=remark3]').val()
                  var password = $enrollDom.find('[name=pw]').val();
                  if(phone==""||ClassInNo==""||cnName==""){
                    return false;
                  }
                    var enroll = {
                      mobile: phone,
                      fullname: fullname,
                      chinesename: cnName,
                      dateofbirth: dateofbirth,
                      sex: sex,
                      curriculum: curriculum,
                      needsubject: needsubject,
                      email: email,
                      classdate: classdate,
                      gradeno: gradeno,
                      textbookname: textbookname,
                      firstLessonContent: firstLessonContent,
                      difficulty: difficulty,
                      currentgrades: currentgrades,
                      lessondate: lessondate,
                      schoolname: schoolname,
                      signupDate:signupDate,
                      ClassInNo:ClassInNo,
		                  remark1:remark1,
                      remark2:remark2,
                      remark3:remark3
                    };
                    if(needPw=false){
                      ajaxMethod({
                          url: '/api/demoment',
                          type: 'post',
                          data: enroll,
                          success: function (data) {
                             window.location.reload();
                           }
                      });
                    }else{
                      ajaxMethod({
                          url: '/api/demoment',
                          type: 'post',
                          data: $.extend({}, enroll, {password: password}),
                          success: function (data) {
                             window.location.reload();
                           }
                      });
                    }
                }
            },
            position: {
                width:656,
                height:554
            }
        })
        $(".popUpBoxFg").find('.close').on("click",function(){
           $enrollDom.find('.pw').hide();
         })

    })
    // 下拉列表
    $("#sel").on('change', function () {
        var val = $(this).val();
        if (val == 'v1') {
            $(".v1").show();
            $(".v2").hide();
        } else if (val == 'v2') {
            $(".v2").show();
            $(".v1").hide();
        } else {

            EnrollList()
        }


    });

    //报名表列表导入功能
    function fileUpload($container) {
        var $uploadInput = $container.find('input')
        var coverUploadInput = new UploadInput({
          formData: {
            importer: 'demo'
          },
          $dom: $uploadInput,
          done: function (uploadSrc) {
	   if(uploadSrc!="true"){
            var $import=$('<div style="padding-left:18px;margin-top:15px;"></div>').html('');
            $.each(uploadSrc,function(index,exce){
               $("<p style='height:30px;line-height:30px;'><label style='display:inline-block;width:85px;'>"+exce.student.chinesename+":</label><label>"+exce.error+"</label></p>").appendTo($import);
            })
          }else{
           var $import=$('<div style="padding-left:18px;margin-top:15px;">'+i18next.t('popupbox.data')+'</div>');//数据已经导入成功！
          }
          var popUpBox = new PopUpBox({
              type: 'dom',
              style: 'default contentScroll',
              submitBtnType: 'confirm',
              keySubmit: false,
              titleText: i18next.t('popupbox.importdata'),//导入信息提示
              show: true,
              content: $import,
              callback: {
                  yes: function (e) {
                    window.location.reload();
                  }
              },
              position: {
                  width:450,
                  height:263
              }
          })
        }
      });
    }

    fileUpload($('#J_container'))
    //搜索功能
    function loadSearchData(querystr) {
        if(querystr) {
            pagination.filter.chinesename = querystr;
            pagination.filter.ClassIn = querystr;

            pagination.searchData()
        } else {
            pagination.reloadData()
        }
    }

    $('#J_teacher_search').on('click', function() {
        var $input = $(this).prev();
        var querystr = $.trim($input.val());
        loadSearchData(querystr)
    })

    $('.searchInput').on('keyup', function(e) {
        if(e.keyCode == 13) {
            var querystr = $.trim($(this).val());
            loadSearchData(querystr)
        }
    })

    //编辑的逻辑
        var $genderWrap = $enrollDom.find('.genderWrap');
        function loadEnrollData(fuid, callback) {
        ajaxMethod({
            url: '/api/demoment/' + fuid,
            dataType: 'json',
            success: function (data) {
                $enrollDom.find('[name=cn_name]').val(data.chinesename);
                $enrollDom.find('[name=en_name]').val(data.fullname);
                $enrollDom.find('[name=phone]').val(data.mobile);
                $enrollDom.find('[name=fuid]').val(data.formuid);
                $enrollDom.find('[name=email]').val(data.email);
                $enrollDom.find('[name=curriculum]').val(data.curriculum);
                $enrollDom.find('[name=needsubject]').val(data.needsubject);
                $enrollDom.find('[name=email]').val(data.email);
                $enrollDom.find('[name=classdate]').val(data.classdate);
                $enrollDom.find('[name="gradeno"]').val(data.gradeno);
                $enrollDom.find('[name=textbookname]').val(data.textbookname);
                $enrollDom.find('[name=firstLessonContent]').val(data.firstLessonContent);
                $enrollDom.find('[name=difficulty]').val(data.difficulty);
                $enrollDom.find('[name=lessondate]').val(data.lessondate);
                $enrollDom.find('[name=currentgrades]').val(data.currentgrades);
                $enrollDom.find('[name=schoolname]').val(data.schoolname);
                $enrollDom.find('[name=ClassInNo]').val(data.ClassInNo);
		$enrollDom.find('[name=remark1]').val(data.remark1);
                $enrollDom.find('[name=remark2]').val(data.remark2);
                $enrollDom.find('[name=remark3]').val(data.remark3);
                $genderWrap.find('input[value="' + data.sex + '"]').click()
                var dateofbirth="";
                if(data.dateofbirth!="0000-00-00 00:00:00"&&data.dateofbirth!=null){
                 dateofbirth= data.dateofbirth.substr(0,10);
                }else{
                  return i18next.t('popupbox.pleasedate') ;//"请选择日期"
                }
                $enrollDom.find('[name=dateofbirth]').val(dateofbirth);
                var signupDate="";
                var da="0000-00-00 00:00:00"
                if(data.signupDate!=da&&data.signupDate!=null){
                 signupDate= data.signupDate.substr(0,10);
                }else{
                    return i18next.t('popupbox.pleasedate') ;//"请选择日期"
                }
                $enrollDom.find('[name=signupDate]').val(signupDate);
               (typeof callback == 'function') && callback()
            }
        })
    }

    function bindSubmit(data,sex) {
          if (FormCheck.childrenInputCheck($enrollDom.find('#J_enroll_wrap'))) {
            var cnName = $enrollDom.find('[name=cn_name]').val()
            var fullname = $enrollDom.find('[name=en_name]').val()
            var phone = $enrollDom.find('[name=phone]').val()
            var dateofbirth = $enrollDom.find('[name=dateofbirth]').val()
            var sex = $enrollDom.find('[name=sex]:checked').val()
            var curriculum = $enrollDom.find('[name=curriculum]').val()
            var needsubject = $enrollDom.find('[name=needsubject]').val()
            var email = $enrollDom.find('[name=email]').val()
            var classdate = $enrollDom.find('[name=classdate]').val()
            var gradeno = $enrollDom.find('[name=gradeno]').val()
            var textbookname = $enrollDom.find('[name=textbookname]').val()
            var firstLessonContent = $enrollDom.find('[name=firstLessonContent]').val()
            var difficulty = $enrollDom.find('[name=difficulty]').val()
            var lessondate = $enrollDom.find('[name=lessondate]').val()
            var currentgrades = $enrollDom.find('[name=currentgrades]').val()
            var schoolname = $enrollDom.find('[name=schoolname]').val()
            var fuid = $enrollDom.find('[name=fuid]').val()
            var signupDate= $enrollDom.find('[name=signupDate]').val()
            var ClassInNo= $enrollDom.find('[name=ClassInNo]').val()
	    var remark1= $enrollDom.find('[name=remark1]').val()
            var remark2= $enrollDom.find('[name=remark2]').val()
            var remark3= $enrollDom.find('[name=remark3]').val()
            var enroll = {
                    mobile: phone,
                    fullname: fullname,
                    chinesename: cnName,
                    dateofbirth: dateofbirth,
                    curriculum: curriculum,
                    needsubject: needsubject,
                    email: email,
                    classdate: classdate,
                  //  studentuid: 0,
                    gradeno: gradeno,
                    sex:sex,
                    textbookname: textbookname,
                    firstLessonContent: firstLessonContent,
                    difficulty: difficulty,
                    currentgrades: currentgrades,
                    lessondate: lessondate,
                    schoolname: schoolname,
                    signupDate:signupDate,
                    ClassInNo:ClassInNo,
                    remark1:remark1,
                    remark2:remark2,
                    remark3:remark3
                }
                if (fuid!=undefined) {
                    ajaxMethod({
                        url: '/api/demoment/'+fuid,
                        type: 'put',
                        data: $.extend(enroll, { formuid:fuid }),
                        success: function (data) {
                          window.location.reload();
                        },
                        error:function (data) {
                          console.log(data.error);
                        }
                    });

                }

            }


    }

   //点击选择的圆点出现预约时间段
    function getEnrollList(arr) {
        ajaxMethod({
            url: '/api/schedules/teachertimes',
            type: 'get',
            dataType: 'json',
            data: arr,
            success: function (data, arr) {
                var $enrollmentTable1 = $AboutClass.find('.appoint-section23').html('');
                var days=data.days;
              $.each(days,function(index,item){
                var a=JSON.stringify(item.day)
                var day=(item.day).replace(/\-/g,"");
                var $div = $('<div data-id='+day+'></div>').appendTo($enrollmentTable1);
                $div.append('<h4 style="margin-top:43px;">' + item.day + ' (' + item.week + ') ' + '</h4>');
                var list=item.list;
                $.each(list,function(index2,item2){
                      var $p = $("<p style='height:41px;margin:24px 0;'></p>").appendTo($div);
                      var spn1 = $('<span class="spn1" style="display:inline-block;width:337px;line-height: 24px;"></span>').appendTo($p);
                      var $courseType=$('<span style="width: 161px;display: inline-block;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;position:relative;top:5px;">'+i18next.t('table.coursetype')+'：' + item2.coursetypename + '</span>').appendTo(spn1);

                      var $lessonName = $('<span style="margin-top:10px;cursor:pointer" class="cursor-edit">'+i18next.t('table.lessonsname')+'：<span style="max-width:68px;display: inline-block;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;position: relative;top: 10px;" class="J_lesson">' + item2.name + '</span></span><br/>')

                      $lessonName.on('click', function() {

                        var beforeVal = item2.name;
                        var $content = $('<div class="formList">\
                          <div class="formLi">\
                            <div class="formTitle">\
                              <span>'+i18next.t('table.lessonsname')+'</span>\
                            </div>\
                            <div class="formContent">\
                              <input class="form-control" type="text" name="lessonname" value="'+ beforeVal +'" style="width:300px;">\
                            </div>\
                          </div>\
                        </div>');
                        var $input = $content.find('[name="lessonname"]');

                        var popUpBox=new PopUpBox({
                          type:'dom',
                          style:'default',
                          submitBtnType:'confirm',
                          titleText:i18next.t('popupbox.edit'),//编辑课节名称
                          content:$content,
                          show: true,
                          callback:{
                            'yes':function(e){
                              var curVal = $.trim($input.val());
                              if(curVal == beforeVal) {
                                _Tips(i18next.t('popupbox.nochange'));//课节名称无变化
                                return false;
                              }

                              if(curVal == '') {
                                  _Tips(i18next.t('popupbox.lessonnoempty')) //课节名称不能为空;
                                return false
                              }

                              ajaxMethod({
                                url: '/api/schedule/' + item2.scheduleid,
                                method: 'put',
                                data: $.extend(item2, { name: curVal}),
                                success: function (data, status) {
                                  if(status.code == 0) {
                                    $lessonName.find('.J_lesson').text(data.name)
                                    popUpBox.close()
                                  }
                                }
                              })

                            }
                          },
                          position:{
                            width:460,
                            height:200
                          }
                        })
                      })


                      spn1.append($lessonName);
                      spn1.append('<span style="padding-right:29px;padding-left:4px;width:161px;display:inline-block;">'+ i18next.t('table.time')+'：' + (item2.begintime.substr(11,5))+'~'+(item2.endtime.substr(11,5)) + ' </span>');
                      spn1.append('<span style="">'+ i18next.t('table.remainingquota')+'：' + item2.quotas + '</span>');
                      var $courseList=$('<ul class="courseList"><li>123456789</li></ul>').appendTo(spn1);
                      var $appointBtn1 = $('<a  class="btn btn-primary" style="position: relative;left:19px;top: -11px;">'+ i18next.t('table.make')+'</a>').appendTo($p);
                      $p.css({
                        "position":"relative",
                      })
                      $AboutClass.find('.courseList').css({
                        "position":"absolute",
                        "top":"7px",
                        "left":"107px",
                        "width":"100px",
                        "height":"auto",
                        "border":"1px solid #ccc",
                        "z-index":"10005",
                        "display":"none",
                        "background":"#fff"

                      })

                      $appointBtn1.on('click',function(){
                        var fuid = $AboutClass.find("#fuid").val();
                           ajaxMethod({
                               url: "/api/demoment/"+fuid+"/appint",
                               dataType: "json",
                               type: 'put',
                               data: {"scheduleid":item2.scheduleid},
                               success:function(data,status){
                                 if(status.code!=0){
                                   var popUpBox=new PopUpBox({
                                     type:'dom',
                                     style:'default',
                                     submitBtnType:'confirm',
                                     titleText:'系统提示！',//编辑课节名称
                                     content:'<p style="margin-left:24px;margin-top:10px;">'+status.message+'</p>',
                                     show: true,
                                     callback:{
                                        yes:{
                                      }
                                     },
                                     position:{
                                       width:420,
                                       height:200
                                     }
                                   })
                                 }else{
                                   window.location.reload();
                                 }

                              }
                          })

                      })


                })

              })
              //排序
                function big() {
                    var tr = $enrollmentTable1.find("div");
                    var initList = [], domArr = [];

                    $.each(tr, function (a, k) {
                        initList[a] = $(this).attr('data-id');
                        console.log(initList[a]);

                    })
                    /* 从大到小排序*/
                    function bigToSmall() {
                        getDom();
                        $.each(domArr, function (i) {
                            $.each(domArr, function (j) {
                                if (domArr[i].attr('data-id') < domArr[j].attr('data-id')) {
                                    mid = domArr[j]; domArr[j] = domArr[i]; domArr[i] = mid;
                                }
                            })
                        })
                        appendDom()
                    }
                    /*取出所有tr放进数组*/
                    function getDom() {
                        $(tr).each(function (m) {
                            domArr[m] = $(this);
                        })
                    }
                    /*将数组中的tr插入tbody(原ul中的li自动删除。DOM元素的特性。) */
                    function appendDom() {
                        $.each(domArr, function (d) {
                            $enrollmentTable1.append(domArr[d]);
                        })
                    }
                    bigToSmall();
                }
                big();
            }
        })
    }

    //按照类型选择老师
    function coursetypes() {
      ajaxMethod({
            url: '/api/coursetypes',
            type: "get",
            dataType: "json",
            success: function (data) {
            cource(data);
            }

        })
    function cource(data) {
          //console.log(data)
          var $cource = $('#cource').html('');
          $('<option>全部</option>').appendTo($cource);
          //$('<option>请选择课程类型</option>').appendTo($cource);
          $cource.css({
              "width": "120px",
              "height": "30px",
              "border": "1px solid #ccc",
              "border-radius": "3px"

          });

          $.each(data, function (index,item) {
            //console.log(item.coursetypeuid);
            $('<option data-cuid='+item.coursetypeuid+'>' + item.coursetypename + '</option>').appendTo($cource);

          })
          $('#cource').on('change',function(){
            var sCoursetypename=$('#cource option:selected').val();
            var sCoursetypeid=$('#cource option:selected').attr('data-cuid');
            var getVal = $("#J_date_search").val();
            appointTeacher(getVal.split('~')[0],getVal.split('~')[1],sCoursetypeid);
            })
        }
    }
    //按照时间选择老师
    function appointTeacher(begintime, endtime,sCoursetypeid) {

        if (begintime == undefined) {
            begintime = new Date().Format('YYYY-MM-DD')
            endtime = new Date(+new Date + 30 * 24 * 3600 * 1000).Format('YYYY-MM-DD')
            $AboutClass.find('#J_date_search').val(begintime + '~' + endtime)
        }
        ajaxMethod({
            url: '/api/schedules/teachers',
            data:{
              begintime: begintime,
              endtime: endtime,
              coursetypeid:sCoursetypeid

            },
            success:function(data){
              timeData(data,sCoursetypeid);
            }
          })

        function  timeData(data,sCoursetypeid){
            var $teacherListData = $AboutClass.find('#J_teacherlist_data').html('')
            $.each(data, function (index, item) {
                var teacheruid = item.teacheruid;
                var chinesename = $AboutClass.find('#studentname').val();
                var needsubject = $AboutClass.find('#needsubject').val();
                $AboutClass.find("#studentname1").html(chinesename);
                $AboutClass.find("#needsubject1").html(needsubject==""?"--":needsubject);
                var $tr = $('<tr class="id' + item.teacherid + '" data-uid="' + item.teacherid + '"></tr>')
                $tr.append('<td>1</td>')
                $tr.append('<td>' + item.teachername + '</td>')
                //$tr.append('<td>' + item.mobile + '</td>')
                $tr.append('<td>' + item.begintime + '</td>')
                $tr.append('<td>' + item.endtime + '</td>')
                $tr.append('<td>' + item.times + '</td>')
                var $radioTd = $('<td></td>').appendTo($tr)
                var $radioIcon = $('<span class="icon icon-size-16 icon-radio" data-type="checkbox" style="postion:relative;left:-3px;">\
                            <input type="checkbox" name="teacher" data-checkedmax="1" value="1" >\
                            </span>').appendTo($radioTd);
                //点击圆点
                $radioIcon.on('click', function () {
                   if ($(this).hasClass('checked')) {
                        $AboutClass.find('.timelist-search').hide()
                    } else {
                        $AboutClass.find('#J_teachername').text(item.teachername)
                        $AboutClass.find('.timelist-search').show()
                        $AboutClass.find(".line").hide();
                            teacherlist(sCoursetypeid);
                        var $parentDom = $AboutClass.find('.appoint-section').html('');
                        var $teacherRemark=$AboutClass.find('.teacherRemark').html('');
                        var  id= $tr.attr('data-uid');
                        ajaxMethod({
                          url:"/api/teacher/"+id,
                          type:"get",
                          success:function(data){
                          $('<a>'+i18next.t('popupbox.remark')+'：</a><li style="display:inline-block;">'+data.remark1+' ,</li><li  style="display:inline-block;padding:0 4px;">'+data.remark2+'</li>').appendTo($teacherRemark);
                            }
                          })
                      }
                })


                function teacherlist(sCoursetypeid) {
                    var arr = {
                        begintime: item.begintime,
                        endtime: item.endtime,
                        teacherid: item.teacherid,
                        coursetypeid:sCoursetypeid

                    }

                    $('.timelist-search').show()
                    $('.prompt').hide();
                   $('#J_appointTimeList').click()
                   getEnrollList(arr);
                }


                $teacherListData.append($tr)
                var $J_teacherlist_select = $AboutClass.find('#J_teacherlist_select');
                var len = $J_teacherlist_select.find('tr').length;
                for (var i = 1; i < len; i++) {
                    $J_teacherlist_select.find('tr:eq(' + i + ') td:first').text(i);
                }
            })
        }

        $AboutClass.find('#J_date_search').on('change', function () {
            var getVal = $(this).val()
            appointTeacher(getVal.split('~')[0], getVal.split('~')[1],'')
        })
    }

    pagination = new Pagination($pagination, EnrollList)
 })
